﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SalePartial.IDAL;
using System.Data.SqlClient;
using SalePartial.Model;

namespace SalePartial.BLL
{
    public class XPCompanyProduct : IXPCompanyProduct
    {
        private IXPCompanyProduct dal = SalePartial.DALFactory.DataAccess.CreateXPCompanyProduct();

        //public void Create()
        //{
        //    XPCompanyProductUtility.Insert(this.ProductID, this.CompanyID, this.ProductName, this.ProductDescription, this.ProductPhotoTitle, this.ProductPhotoFile, this.CreateUserID, this.CreateDate, this.LastUpdateDate, this.ModerateStatus,
        //    this.ModerateDate, this.ModerateUserID, this.Comments);
        //}

        public void Delete(XPCompanyProductInfo info)
        {
            dal.Delete(info.ProductID);
        }

        public XPCompanyProductInfo GetXPCompanyProduct(Guid id)
        {
            XPCompanyProductInfo info = null;
            SqlDataReader reader = this.SelectReader(id);
            if (reader.Read())
            {
                info = new XPCompanyProductInfo(reader);
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }

            return info;
        }


        //public static XPCompanyProductInfo NewXPCompanyProduct(Guid id)
        //{
        //    return new XPCompanyProductInfo { _productID = id };
        //}

        //public void Update()
        //{
        //    this.LastUpdateDate = DateTime.Now;
        //    XPCompanyProductUtility.Update(this.ProductID, this.CompanyID, this.ProductName, this.ProductDescription, this.ProductPhotoTitle, this.ProductPhotoFile, this.CreateUserID, this.CreateDate, this.LastUpdateDate, this.ModerateStatus,
        //    this.ModerateDate, this.ModerateUserID, this.Comments);
        //}

        public int Delete(Guid ProductID)
        {
            return dal.Delete(ProductID);
        }

        public int DeleteByCompanyID(Guid CompanyID)
        {
            return dal.DeleteByCompanyID(CompanyID);
        }

        public int DeleteDynamic(string v_whereCondition)
        {
            return dal.DeleteDynamic(v_whereCondition);
        }

        public int Insert(XPCompanyProductInfo info)
        {
            return dal.Insert(info);
        }

        public System.Data.DataSet SelectAll()
        {
            return dal.SelectAll();
        }

        public System.Data.DataSet SelectByCompanyID(Guid CompanyID)
        {
            return dal.SelectByCompanyID(CompanyID);
        }

        public List<XPCompanyProductInfo> SelectInfoByCompanyID(Guid CompanyID)
        {
            SqlDataReader reader = this.SelectReaderByCompanyID(CompanyID);
            List<XPCompanyProductInfo> infoList = new List<XPCompanyProductInfo>();
            while (reader.Read())
            {
                XPCompanyProductInfo info = new XPCompanyProductInfo(reader);
                infoList.Add(info);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }

            return infoList;

        }
        public System.Data.DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            return dal.SelectDynamic(v_whereCondition, v_orderByExpression);
        }

        public System.Data.DataSet SelectPaged()
        {
            return dal.SelectPaged();
        }

        public System.Data.SqlClient.SqlDataReader SelectReader(Guid ProductID)
        {
            return dal.SelectReader(ProductID);
        }

        public System.Data.SqlClient.SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            return dal.SelectReaderByCompanyID(CompanyID);
        }

        public System.Data.DataSet SelectSingle(Guid ProductID)
        {
            return dal.SelectSingle(ProductID);
        }

        public int Update(XPCompanyProductInfo info)
        {
            return dal.Update(info);
        }
    }
}
